package com.hww.web;

import com.alibaba.fastjson.JSONObject;
import com.hww.entity.TestUser;
import com.hww.mapper.TestUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.Collator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

/**
 * @Author: heweiwei
 * @Date: 1/9/25 PM2:03
 * @Description:
 */
@RestController
public class TestUserController {

    @Autowired
    private TestUserMapper testUserMapper;

    @RequestMapping("/listUser")
    public void listUser() {
        List<TestUser> testUsers = testUserMapper.listUser();

        List<TestUser> collect = testUsers.stream().sorted((i1, i2) -> Collator.getInstance(Locale.SIMPLIFIED_CHINESE).compare(i1.getUserName().substring(0,1), i2.getUserName().substring(0,1))).collect(Collectors.toList());

        System.out.println("testUsers = " + JSONObject.toJSONString(collect));
    }
}
